package com.ldzy.dao;

import com.github.pagehelper.Page;
import com.ldzy.pojo.Room;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface RoomMapper {
    @Select("<script>"+
            "select * from room "+
            "<where>"+
            "<if test=\"roomname != null\"> AND  roomname like  CONCAT('%',#{roomname},'%')</if>" +
            "<if test=\"price != null\"> AND price like  CONCAT('%', #{price},'%') </if>" +
            "<if test=\"tenement != null\"> AND tenement like  CONCAT('%', #{tenement},'%')</if>" +
            "</where>"+
            "order by id "+
            "</script>")
    public Page<Room> selectNewRooms(Room room);
    @Select("select * from room where id=#{id}")
    public Room findById(int id);
    @Update("<script> " +
            "update room"+
            "<set>"+
            "<if test=\"roomname != null\" >" +
            "     roomname = #{roomname}," +
            " </if>" +
            " <if test=\"price != null\" >" +
            "     price = #{price}," +
            " </if>" +
            " <if test=\"tenement != null\" >" +
            "     tenement = #{tenement}," +
            " </if>" +
            " <if test=\"age != null\" >" +
            "     age = #{age}," +
            " </if>" +
            " <if test=\"status != null\" >" +
            "     status = #{status}," +
            " </if>" +
            "</set> " +
            "where roomname=#{roomname}"+
            "</script>")
    public int edit(Room room);
    @Select("<script>" +
            "select * from room where status='1'"+
            "<if test=\"roomname != null\"> AND  roomname like  CONCAT('%',#{roomname},'%')</if>" +
            "<if test=\"price != null\"> AND price like  CONCAT('%', #{price},'%') </if>" +
            "<if test=\"tenement != null\"> AND tenement like  CONCAT('%', #{tenement},'%')</if>" +
            "order by id" +
            "</script>")
    Page<Room> selectBorrowedRooms(Room room);
}
